import {keyWords} from '/static/keywords/keywords.js'

// 时间戳转换函数
export function convertTimestampToDate(timestamp) {
    const date = new Date(timestamp);
    
    // 获取年、月、日
    const year = date.getFullYear();
    const month = ('0' + (date.getMonth() + 1)).slice(-2); // 加1是因为getMonth返回的是0-11
    const day = ('0' + date.getDate()).slice(-2);
    
    // 组合成想要的格式
    return `${year}-${month}-${day}`;
}

// 如果需要更多时间相关的工具函数，可以在这里添加
export function formatDateTime(timestamp) {
    const date = new Date(timestamp);
    const year = date.getFullYear();
    const month = ('0' + (date.getMonth() + 1)).slice(-2);
    const day = ('0' + date.getDate()).slice(-2);
    const hour = ('0' + date.getHours()).slice(-2);
    const minute = ('0' + date.getMinutes()).slice(-2);
    
    return `${year}-${month}-${day} ${hour}:${minute}`;
}

 // 过滤敏感词
export function filterSensitiveWords(text) {
     let foundKeywords = [];
     keyWords.forEach(keyword => {
         if (text.includes(keyword)) {
             foundKeywords.push(keyword);
         }
     });
     return foundKeywords.length > 0 ? foundKeywords : null;
 }
 
 